package com.xuwang.controller;

import com.xuwang.mapper.GovernmentStaffGMapper;
import com.xuwang.pojo.GovernmentStaffG;
import com.xuwang.pojo.WorkLogG;
import com.xuwang.service.impl.WorkLogServiceGGImpl;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.sql.Date;
import java.text.ParseException;
import java.util.Map;

/**
 * @ClassName WorkLogController
 * @Description TODO
 * @Author gongzihao
 * @Date 2021/9/14 15:59
 */

@Api(value = "WorkLogController",tags = "工作日志接口")
@RestController
@RequestMapping("/workLog")
public class WorkLogController {



    @Resource
    WorkLogServiceGGImpl workLogService ;

    @Resource
    GovernmentStaffGMapper governmentStaffGMapper;


    /**
     *  通过logId查询相关工作日志
     *  通过模糊查询政府部门名查询相关部门下的所有工作日志
     *  通过模糊查询政府部门工作人员的姓名查询旗下的工作日志
     * @return
     */
    @GetMapping("/testWorkLogSelectAll")
    public Map<String,Object> testWorkLogSelectAll (Integer id ,
                                                    String departmentName,
                                                    String staffName,
                                                    String logCreateTime,
                                                    @RequestParam("page") String page,
                                                    @RequestParam("limit")String limit){
        return workLogService.selectAll(id,departmentName,staffName,logCreateTime,Integer.parseInt(page),Integer.parseInt(limit));
    }


    /**
     * @param log
     * @param request
     * @return
     */
    @PostMapping("/testWorkLogInsert")
    public Map<String,Object> testWorkLogInsert (String log, HttpServletRequest request) throws ParseException {
//        String authorization = request.getHeader("Authorization");
//        DecodedJWT tokenInfo = JWTUtil.getTokenInfo(authorization);
//        int staffId = tokenInfo.getClaim("staffId").asInt();
//        GovernmentStaffG governmentStaffG = governmentStaffGMapper.selectById(staffId);
////        GovernmentStaff governmentStaff  =  governmentStaffSevice.selectStaffById(staffId);
        WorkLogG workLogG = null;
//        if(staffId== governmentStaffG.getId()){
        GovernmentStaffG governmentStaffG = governmentStaffGMapper.selectById(3);
            workLogG = new WorkLogG();
            workLogG.setLog(log);
            workLogG.setGovernmentDepartmentId(governmentStaffG.getGovernmentDepartmentId());
            workLogG.setGovernmentStaffId(governmentStaffG.getId());
//            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
            workLogG.setLogCreateTime(new Date(System.currentTimeMillis()));
//        }else {
//            Map<String,Object> map = new HashMap<>();
//            map.put("code",500);
//            map.put("msg","对不起,您的权限不够");
//            return map;
//        }

        return  workLogService.logInsert(workLogG);
    }
}
